package com.ruoyi.mobile.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.mobile.service.MaterialService;
import com.ruoyi.mobile.service.MaterialjkService;
import com.ruoyi.mobile.utils.NftResponse;
import com.ruoyi.mobile.utils.Paginator;
import com.ruoyi.mobile.utils.ResponseConstants;
import com.ruoyi.system.api.req.*;
import com.ruoyi.system.api.resp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/usermat")
@Api(tags = "用户资料模块")
public class UserMaterialController {
    @Autowired
    private MaterialService materialService;
    @Autowired
    private MaterialjkService materialjkService;

    @ApiOperation(value="资料年级")
    @RequestMapping(value = "/getGrades", method = RequestMethod.GET)
    public NftResponse<List<DictResp>> getGrades() {
        return materialService.getGrades();
    }
    @ApiOperation(value="资料科目")
    @RequestMapping(value = "/getSubjects", method = RequestMethod.GET)
    public NftResponse<List<DictResp>> getSubjects() {
        return materialService.getSubjects();
    }
    @ApiOperation(value="资料学期")
    @RequestMapping(value = "/getSemesters", method = RequestMethod.GET)
    public NftResponse<List<DictResp>> getSemesters() {
        return materialService.getSemesters();
    }
    @ApiOperation(value="资料年份")
    @RequestMapping(value = "/getAges", method = RequestMethod.GET)
    public NftResponse<List<Integer>> getAges() {
        return materialService.getAges();
    }

    @ApiOperation(value="资料列表")
    @RequestMapping(value = "/getMaterialList", method = RequestMethod.POST)
    public NftResponse<Paginator<MaterialInfoResp>> getMaterialList(@RequestBody MaterialInfoReq query) {
        return materialService.getMaterialList(query);
    }
    @ApiOperation(value="资料订单")
    @RequestMapping(value = "/getOrderList", method = RequestMethod.POST)
    public NftResponse<Paginator<MaterialOrderResp>> getOrderList(@RequestBody MaterialOrderReq query) {
        return materialService.getOrderList(query);
    }
    @ApiOperation(value="资料下载")
    @RequestMapping(value = "/getDownList", method = RequestMethod.POST)
    public NftResponse<Paginator<MaterialDownResp>> getDownList(@RequestBody MaterialDownReq query) {
        return materialService.getDownList(query);
    }
    @ApiOperation(value="资料浏览")
    @RequestMapping(value = "/getViewList", method = RequestMethod.POST)
    public NftResponse<Paginator<MaterialViewResp>> getViewList(@RequestBody MaterialViewReq query) {
        return materialService.getViewList(query);
    }
    @ApiOperation(value="资料收藏")
    @RequestMapping(value = "/getCollectList", method = RequestMethod.POST)
    public NftResponse<Paginator<MaterialCollectResp>> getCollectList(@RequestBody MaterialCollectReq query) {
        return materialService.getCollectList(query);
    }
    @ApiOperation(value="资料详细")
    @RequestMapping(value = "/getMaterialInfo", method = RequestMethod.GET)
    public NftResponse<MaterialInfoResp> getMaterialInfo(@RequestParam("id") Long id, @RequestParam("userId") Long userId) {
        return materialService.getMaterialInfo(id, userId);
    }

    @ApiOperation(value="创建资料订单")
    @RequestMapping(value = "/createOrderzl", method = RequestMethod.PUT)
    public NftResponse<JSONObject> createOrderzl(@RequestBody MaterialOrderReq query) {
        try {
            return materialService.insertOrderInfo(query);
        }catch (Exception e){
            return new NftResponse<>(ResponseConstants.SUCCESS_CODE, "下单失败", null);
        }
    }
    @ApiOperation(value="资料下载")
    @RequestMapping(value = "/createDown", method = RequestMethod.PUT)
    public NftResponse<Boolean> createDown(@RequestBody MaterialDownReq query) {
        try {
            return materialService.insertDownInfo(query);
        }catch (Exception e){
            return new NftResponse<>(ResponseConstants.SUCCESS_CODE, "下单失败", null);
        }
    }
    @ApiOperation(value="资料收藏")
    @RequestMapping(value = "/createCollect", method = RequestMethod.PUT)
    public NftResponse<JSONObject> createCollect(@RequestBody MaterialCollectReq query) {
        try {
            return materialService.insertCollectInfo(query);
        }catch (Exception e){
            return new NftResponse<>(ResponseConstants.SUCCESS_CODE, "下单失败", null);
        }
    }
    @ApiOperation(value="资料浏览")
    @RequestMapping(value = "/createView", method = RequestMethod.PUT)
    public NftResponse<JSONObject> createView(@RequestBody MaterialViewReq query) {
        try {
            return materialService.insertViewInfo(query);
        }catch (Exception e){
            return new NftResponse<>(ResponseConstants.SUCCESS_CODE, "下单失败", null);
        }
    }

    @ApiOperation(value="删除资料订单")
    @RequestMapping(value = "/delOrderzl", method = RequestMethod.POST)
    public NftResponse<Boolean> delOrderzl(@RequestBody SchoolConsumeReq query) {
        return materialService.delOrderzl(query.getId());
    }
    @ApiOperation(value="删除资料下载")
    @RequestMapping(value = "/delDownzl", method = RequestMethod.POST)
    public NftResponse<Boolean> delDownzl(@RequestBody SchoolConsumeReq query) {
        return materialService.delDownzl(query.getId());
    }
    @ApiOperation(value="删除资料收藏")
    @RequestMapping(value = "/delCollectzl", method = RequestMethod.POST)
    public NftResponse<Boolean> delCollectzl(@RequestBody SchoolConsumeReq query) {
        return materialService.delCollectzl(query.getId());
    }
    @ApiOperation(value="删除资料浏览")
    @RequestMapping(value = "/delViewzl", method = RequestMethod.POST)
    public NftResponse<Boolean> delViewzl(@RequestBody SchoolConsumeReq query) {
        return materialService.delViewzl(query.getId());
    }

    @ApiOperation(value="句块列表")
    @RequestMapping(value = "/getMaterialjkList", method = RequestMethod.POST)
    public NftResponse<Paginator<MaterialInfojkResp>> getMaterialjkList(@RequestBody MaterialInfojkReq query) {
        return materialjkService.getMaterialjkList(query);
    }
    @ApiOperation(value="句块订单")
    @RequestMapping(value = "/getOrderjkList", method = RequestMethod.POST)
    public NftResponse<Paginator<MaterialjkOrderResp>> getOrderjkList(@RequestBody MaterialjkOrderReq query) {
        return materialjkService.getOrderList(query);
    }
    @ApiOperation(value="句块收藏")
    @RequestMapping(value = "/getCollectjkList", method = RequestMethod.POST)
    public NftResponse<Paginator<MaterialjkCollectResp>> getCollectjkList(@RequestBody MaterialjkCollectReq query) {
        return materialjkService.getCollectList(query);
    }
    @ApiOperation(value="句块详细")
    @RequestMapping(value = "/getMaterialInfojk", method = RequestMethod.GET)
    public NftResponse<MaterialInfojkResp> getMaterialInfojk(@RequestParam("id") Long id, @RequestParam("userId") Long userId) {
        return materialjkService.getMaterialInfo(id, userId);
    }
    @ApiOperation(value="获取句块翻译结果")
    @RequestMapping(value = "/getMaterialInfojkt", method = RequestMethod.GET)
    public NftResponse<MaterialInfojkResp> getMaterialInfojkt(@RequestParam("id") Long id, @RequestParam("userId") Long userId) {
        return materialjkService.getMaterialInfot(id, userId);
    }
    @ApiOperation(value="播放句块语音")
    @RequestMapping(value = "/playVoice", method = RequestMethod.GET)
    public NftResponse<String> playVoice(@RequestParam("id") Long id, @RequestParam("userId") Long userId) {
        return materialjkService.playVoice(id, userId);
    }
    @ApiOperation(value="创建句块订单")
    @RequestMapping(value = "/createOrderjk", method = RequestMethod.PUT)
    public NftResponse<JSONObject> createOrderjk(@RequestBody MaterialjkOrderReq query) {
        try {
            return materialjkService.insertOrderInfo(query);
        }catch (Exception e){
            return new NftResponse<>(ResponseConstants.SUCCESS_CODE, "下单失败", null);
        }
    }
    @ApiOperation(value="创建句块订单")
    @RequestMapping(value = "/createOrderjkt", method = RequestMethod.PUT)
    public NftResponse<JSONObject> createOrderjkt(@RequestBody MaterialjkOrderReq query) {
        try {
            return materialjkService.insertOrderInfot(query);
        }catch (Exception e){
            return new NftResponse<>(ResponseConstants.SUCCESS_CODE, "下单失败", null);
        }
    }
    @ApiOperation(value="句块收藏")
    @RequestMapping(value = "/createCollectjk", method = RequestMethod.PUT)
    public NftResponse<JSONObject> createCollectjk(@RequestBody MaterialjkCollectReq query) {
        try {
            return materialjkService.insertCollectInfo(query);
        }catch (Exception e){
            return new NftResponse<>(ResponseConstants.SUCCESS_CODE, "下单失败", null);
        }
    }
    @ApiOperation(value="句块是否掌握")
    @RequestMapping(value = "/createHoldjk", method = RequestMethod.PUT)
    public NftResponse<JSONObject> createHoldjk(@RequestBody MaterialjkViewReq query) {
        try {
            return materialjkService.insertHoldInfojk(query);
        }catch (Exception e){
            return new NftResponse<>(ResponseConstants.SUCCESS_CODE, "下单失败", null);
        }
    }
    @ApiOperation(value="删除句块订单")
    @RequestMapping(value = "/delOrderjk", method = RequestMethod.POST)
    public NftResponse<Boolean> delOrderjk(@RequestBody SchoolConsumeReq query) {
        return materialjkService.delOrderjk(query.getId());
    }
    @ApiOperation(value="删除句块收藏")
    @RequestMapping(value = "/delCollectjk", method = RequestMethod.POST)
    public NftResponse<Boolean> delCollectjk(@RequestBody SchoolConsumeReq query) {
        return materialjkService.delCollectjk(query.getId());
    }
}
